package com.su.controller;

import com.su.pojo.Book;
import com.su.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/view")
public class ViewController {
    @Autowired
    private BookService bookService;

    @RequestMapping("/toList")
    public String toList() {
        return "list";
    }

    @RequestMapping("/toAddBook")
    public String toAddBook() {
        return "addBook";
    }

    @RequestMapping("/toUpdateBook")
    public String toUpdateBook(String bookId, HttpServletRequest request) {
        Book book = bookService.getBookById(Integer.parseInt(bookId));
        List<Integer> booktypes = bookService.getBookType();
        System.out.println(book);
        request.setAttribute("book", book);
        request.setAttribute("bookTypeList", booktypes);
        return "edit";
    }

    @RequestMapping("/toBatchBook")
    public String toBatchBook(){
        return "batchImport";
    }


}
